package net.xiangcaowuyu.shiro.service.impl;

import net.xiangcaowuyu.shiro.entity.ShiroRole;
import net.xiangcaowuyu.shiro.entity.ShiroUser;
import net.xiangcaowuyu.shiro.mapper.ShiroUserMapper;
import net.xiangcaowuyu.shiro.service.ShiroRoleService;
import net.xiangcaowuyu.shiro.service.ShiroService;
import net.xiangcaowuyu.shiro.service.ShiroUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author laughing
 * @date 2020/10/11
 * @site https://www.lisen.org
 */
@Service
public class ShiroUserServiceImpl implements ShiroUserService {

    @Resource
    ShiroUserMapper shiroUserMapper;

    @Resource
    ShiroRoleService shiroRoleService;

    /**
     * 根据用户编号获取
     *
     * @param userCode 用户编号
     * @return 用户
     */
    @Override
    public ShiroUser findUserByUserCode(String userCode) {
        ShiroUser shiroUser = shiroUserMapper.findUserByUserCode(userCode);
        Set<ShiroRole> shiroRoleSet = shiroRoleService.findByUserCode(userCode);
        shiroUser.setShiroRoleSet(shiroRoleSet);
        return shiroUser;
    }

    /**
     * 插入
     *
     * @param shiroUser
     * @return
     */
    @Override
    public int insert(ShiroUser shiroUser) {
        return shiroUserMapper.insert(shiroUser);
    }

    /**
     * 查找所有用户
     *
     * @return
     */
    @Override
    public List<ShiroUser> findAll() {
        return shiroUserMapper.findAll();
    }
}
